//package com.heima.filter;
//
//import com.alibaba.fastjson.JSONObject;
//import com.heima.pojo.Result;
//import com.heima.utils.JwtUtils;
//import org.springframework.util.StringUtils;
//
//import javax.servlet.*;
//import javax.servlet.annotation.WebFilter;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
//@WebFilter("/*")
//public class demo implements Filter {
//
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        HttpServletRequest req = (HttpServletRequest) servletRequest;
//        HttpServletResponse resp = (HttpServletResponse) servletResponse;
//        String url = req.getRequestURL().toString();
//        if (url.contains("/login")){
//            filterChain.doFilter(req,resp);
//            return;
//        }
//        String token = req.getHeader("token");
//        if (!StringUtils.hasLength(token)){
//            Result error = Result.error("NOT_LOGIN");
//            String s = JSONObject.toJSONString(error);
//            resp.setContentType("text/json;charset=utf-8");
//            resp.getWriter().write(s);
//            return;
//        }
//        try {
//            JwtUtils.parseJWT(token);
//        } catch (Exception e) {
//            Result error = Result.error("NOT_LOGIN");
//            String s = JSONObject.toJSONString(error);
//            resp.setContentType("text/json;charset=utf-8");
//            resp.getWriter().write(s);
//            return;
//        }
//        filterChain.doFilter(req,resp);
//    }
//}
